<?php


namespace app\web\controller;


use app\web\model\Comments;
use app\web\model\TableReturn;
use think\Controller;
use think\Db;
use think\facade\Request;

class Data extends Controller
{
    public function findData()
    {
        $page = Request::get('page');
        $limit = Request::get('limit');
        $theme = Request::get('Theme');
        $emotional = Request::get('Emotional');
        if ($theme != null) {
            if ($emotional != null) {
                $data = Comments::where('Theme', $theme)->where('Emotional', $emotional)->limit($limit)->page($page)->selectOrFail();
                $count = Comments::where('Theme', $theme)->where('Emotional', $emotional)->count();
            } else {
                $data = Comments::where('Theme', $theme)->limit($limit)->page($page)->selectOrFail();
                $count = Comments::where('Theme', $theme)->count();
            }
        } else {
            if ($emotional != null) {
                $data = Comments::limit($limit)->where('Emotional', $emotional)->page($page)->selectOrFail();
                $count = Comments::where('Emotional', $emotional)->count();
            } else {
                $data = Comments::limit($limit)->page($page)->selectOrFail();
                $count = Comments::count();
            }
        }

        $obj = new TableReturn();
        $obj->code = 0;
        $obj->msg = '';
        $obj->count = $count;
        $obj->data = $data;
        return json($obj);
    }

    public function remove()
    {
        $data = Request::get();
        $r = db('comments')->where($data)->delete();
        if ($r == 1) {
            return true;
        }
        return false;
    }
}